#!/usr/bin/env python
#################################################################################
#   Copyright (C) 2007 Daniel Kersten / Tim Kersten                             #
#   (See the file AUTHORS for details.)                                         #
#                                                                               #
#   Nexus-Ed is free software; you can redistribute it and/or modify            #
#   it under the terms of the GNU General Public License as published by        #
#   the Free Software Foundation; either version 2 of the License, or           #
#   (at your option) any later version.                                         #
#                                                                               #
#   Nexus-Ed is distributed in the hope that it will be useful,                 #
#   but WITHOUT ANY WARRANTY; without even the implied warranty of              #
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the                #
#   GNU General Public License for more details.                                #
#                                                                               #
#   You should have received a copy of the GNU General Public License           #
#   along with Nexus-Ed; if not, write to the Free Software                     #
#   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA    #
#   or visit http://www.gnu.org/licenses/gpl.txt                                #
#                                                                               #
#################################################################################


VERSION = "0.0.1"

import sys, os
try:
	import pygtk
	pygtk.require("2.0")
except:
	print "Could not import pygtk"

try:
	import gtk
	import gtk.glade
except:
	print "Could not import gtk"
	sys.exit(1)

import tray
from networkhandler import NetworkHandler
from editor import Editor

class Nexus:
	"""
	The main interface class
	"""
	
	def __init__(self):
		"""
		Initialise the main window
		"""
		
		self.version = VERSION
		
		self.net = NetworkHandler()

		self.title = "Nexus"
		self.gladefile = "nexus.glade"
		self.xml = gtk.glade.XML(self.gladefile)
		self.window = self.xml.get_widget("mainWindow")
		self.toolbar = self.xml.get_widget("toolbar")
		self.toolbar.set_style(gtk.TOOLBAR_ICONS)
		self.edNotebook = self.xml.get_widget("edNotebook")
		sci = Editor(self.net, 1)
		self.edNotebook.insert_page(sci.get(), gtk.Label("*untitled"))
		self.peerBox = self.xml.get_widget("peerBox")
		peerSci = Editor(self.net, 2)
		self.peerBox.add(peerSci.get())

		self.window.set_size_request(768, 512)

		self.window.show()
#		self.active = False

#		if tray.TRAY_AVAILABLE:
#			menu = tray.Menu()
#			#menu.append("Display/Hide", self.display)
#			#menu.append_separator()
#			menu.append("Quit", self.quit)
#			self.tray_icon = tray.TrayIcon(self, "trayicon.png", menu)
#			self.tray_icon.set_tooltip("a10 editor " + self.version)
#			self.tray_icon.activate = self.activate
		
		self.connectEvents()

	def connectEvents(self):
		"""
		Connect events to the various widgets
		"""
		
		self.window.connect("delete_event", self.on_Close)


	def on_Close(self, widget=None, event=None):
#		self.window.hide()
#		self.active = False
#		self.palette.close()
#		return True
		gtk.main_quit()

if __name__ == "__main__":
	nexus = Nexus()
	gtk.main()
